package com.ysqcould.activity.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ysqcould.activity.domain.ActivityApplyCustom;
import com.ysqcould.activity.mapper.ActivityApplyCustomMapper;
import com.ysqcould.activity.service.IActivityApplyCustomService;
import com.ysqcould.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 活动报名展示自定字段Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class ActivityApplyCustomServiceImpl implements IActivityApplyCustomService
{
    @Autowired
    private ActivityApplyCustomMapper activityApplyCustomMapper;

    /**
     * 查询活动报名展示自定字段
     * 
     * @param id 活动报名展示自定字段主键
     * @return 活动报名展示自定字段
     */
    @Override
    public ActivityApplyCustom selectActivityApplyCustomById(Long id)
    {
        return activityApplyCustomMapper.selectActivityApplyCustomById(id);
    }

    /**
     * 查询活动报名展示自定字段列表
     * 
     * @param activityApplyCustom 活动报名展示自定字段
     * @return 活动报名展示自定字段
     */
    @Override
    public List<ActivityApplyCustom> selectActivityApplyCustomList(ActivityApplyCustom activityApplyCustom)
    {
        return activityApplyCustomMapper.selectActivityApplyCustomList(activityApplyCustom);
    }

    /**
     * 新增活动报名展示自定字段
     * 
     * @param activityApplyCustom 活动报名展示自定字段
     * @return 结果
     */
    @Override
    public int insertActivityApplyCustom(ActivityApplyCustom activityApplyCustom)
    {
        activityApplyCustom.setCreateTime(DateUtils.getNowDate());
        List<String>list=new ArrayList<>();
        String data="";
        JSONArray domains = activityApplyCustom.getDomains();
        for (int i = 0; i <domains.size() ; i++) {
            String value = domains.getJSONObject(i).getString("value");
            list.add(value);
        }
        if (list.size()>0){
            data = list.stream().collect(Collectors.joining(","));
        }
        activityApplyCustom.setData(data);
        return activityApplyCustomMapper.insertActivityApplyCustom(activityApplyCustom);
    }

    /**
     * 修改活动报名展示自定字段
     * 
     * @param activityApplyCustom 活动报名展示自定字段
     * @return 结果
     */
    @Override
    public int updateActivityApplyCustom(ActivityApplyCustom activityApplyCustom)
    {
        activityApplyCustom.setUpdateTime(DateUtils.getNowDate());
        return activityApplyCustomMapper.updateActivityApplyCustom(activityApplyCustom);
    }

    /**
     * 批量删除活动报名展示自定字段
     * 
     * @param ids 需要删除的活动报名展示自定字段主键
     * @return 结果
     */
    @Override
    public int deleteActivityApplyCustomByIds(Long[] ids)
    {
        return activityApplyCustomMapper.deleteActivityApplyCustomByIds(ids);
    }

    /**
     * 删除活动报名展示自定字段信息
     * 
     * @param id 活动报名展示自定字段主键
     * @return 结果
     */
    @Override
    public int deleteActivityApplyCustomById(Long id)
    {
        return activityApplyCustomMapper.deleteActivityApplyCustomById(id);
    }
}
